﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.IO;
using System.Web.Core;

namespace Yuanlin.Business
{
    public class ServiceTermsAddControl : YuanlinUserControl
    {
        protected ValuedTextBox leftMenuNameValuedTextBox;
        protected ValuedEditor descriptionValuedEditor;
        protected ValuedTextBox orderByValuedTextBox;

        protected IButton SaveButton;
        protected IButton BackButton;

        protected override void OnLoad(EventArgs e)
        {
            SaveButton.Click += new EventHandler(SaveButton_Click);
            BackButton.Click += new EventHandler(BackButton_Click);
        }

        public void BackButton_Click(object sender, EventArgs e)
        {
            Page.Response.Redirect(SiteUrls.Instance().GetServiceTermsListUrl());
        }

        public void SaveButton_Click(object sender, EventArgs e)
        {
            ServiceTerms serviceTerms = new ServiceTerms();

            serviceTerms.LeftMenuName.Value = CensorWordManager.CensorWord(this.leftMenuNameValuedTextBox.Value);
            serviceTerms.Body.Value = CensorWordManager.CensorWord( this.descriptionValuedEditor.Value);
            serviceTerms.OrderBy.Value = Int32.Parse(this.orderByValuedTextBox.Value.Trim());

            if (BusinessManager.CreateServiceTerms(serviceTerms) == -2)
            {
                Globals.ShowMessage(this.Page, "添加失败", "此信息已经存在！");
                return;
            }

            Page.Response.Redirect(SiteUrls.Instance().GetServiceTermsListUrl());
        }
    }
}